﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%--<x:parse xml="${param.xmlstr}" var="xmlData" />--%>
<div class="t_bar">

    <span class="color_red">*</span>
    项目进度计划（最多添加5条）

</div>
<table  id="tblMileStones" style="width: 100%" cellpadding="0" class="table01" width="100%" border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;">
    <thead >
    <tr style="border:1px solid #B7D1E6">
        <th class="TblHead" align="center"  width="30px">选择</th>
        <th class="TblHead" align="center"  width="30px">序号</th>
        <th class="TblHead" align="center"  width="125px">开始时间</th>
        <th class="TblHead" align="center"  width="125px">结束时间</th>
        <th class="TblHead" align="center"  >阶段目标、实施内容、完成任务的措施，取得阶段性成效（限500字）</th>
    </tr>
    </thead>
    <tbody id="tab">
    <tr style="display:none">
        <td>&nbsp;
            <input type="radio" class="radiobutton" name="selMileStones" >
        </td>
        <td align="center">&nbsp;
            <span name="milestones|milestone[0]@seq_no" >[index]</span>
        </td>
        <td align="center">&nbsp;
            <input  id="milestone_start_date_[0]" name="milestones|milestone[0]|start_date" label="开始时间" value="" class=" required input_text date  dateCompare:milestone_end_date_[0] dateCompareAfterE:milestone_start_date_[0]:start_date dateCompareAfterEStep:milestone_start_date_[1]:milestone_end_date_[0]" style="width:65%" label="开始时间" onchange="assignmentDate()"/>
        </td>
        <td align="center">&nbsp;<input  id="milestone_end_date_[0]" name="milestones|milestone[0]|end_date" label="结束时间" value="" class=" required input_text date dateCompareBeforeE:milestone_end_date_[0]:end_date " style="width:65%" label="结束时间" onchange="assignmentDate()"/> </td>
        <td>&nbsp;<textarea name="milestones|milestone[0]|content" class="input_textarea required maxlength:500" label="阶段目标、实施内容、完成任务的措施，取得阶段性成效"  rows=5 style="width:98%"></textarea>
            <input type="hidden" name="milestones|milestone[0]|content_hidden" />
        </td>
    </tr>


    <c:set value="0" var="index" scope="page"/>
    <x:forEach select="$xmlData/data/milestones/milestone" var="milestone">

        <c:choose>
            <c:when test="${index<10}" ><c:set value="0" var="flag" scope="page"/></c:when>
            <c:otherwise><c:set value="" var="flag" scope="page"/></c:otherwise>
        </c:choose>
        <tr>
            <td>&nbsp;
                <input type="radio" class="radiobutton" name="selMileStones" >
            </td>
            <td align="center">
                <span   name="milestones/milestone[${flag}${index}]@seq_no" ><x:out select="$milestone/@seq_no"/></span>
            </td>
            <td align="center">&nbsp;
                <c:set var="start_date" scope="page"><x:out select="$milestone/start_date"/></c:set>
                <input  id="milestone_start_date_[${flag}${index}]" value="${start_date}" label="开始时间" name="milestones/milestone[${flag}${index}]/start_date" class="required date input_text dateCompare:milestone_end_date_[${flag}${index}] dateCompareAfterE:milestone_start_date_[${flag}${index}]:start_date dateCompareAfterEStep:milestone_start_date_[${flag}${index+1}]:milestone_end_date_[${flag}${index}]"  style="width:65%" label="开始时间" onchange="assignmentDate()"/>
            </td>
            <td align="center">&nbsp;
                <c:set var="end_date" scope="page"><x:out select="$milestone/end_date"/></c:set>
                <input  id="milestone_end_date_[${flag}${index}]" name="milestones/milestone[${flag}${index}]/end_date" label="结束时间" value="${end_date}" class="required date input_text dateCompareBeforeE:milestone_end_date_[${flag}${index}]:end_date dateCompareAfterEStep:milestone_end_date_[${flag}${index+1}]:milestone_end_date_[${flag}${index}]" style="width:65%" label="结束时间" onchange="assignmentDate()" /> </td>
            <td>&nbsp;
                <textarea name="milestones/milestone[${flag}${index}]/content" class="input_textarea required maxlength:500" label="阶段目标、实施内容、完成任务的措施，取得阶段性成效" rows=5 style="width:98%;word-break: break-all;"><x:out select="$milestone/content"/></textarea>
                <input type="hidden" name="milestones/milestone[${flag}${index}]/content_hidden" id="milestones/milestone[${flag}${index}]/content_hidden" value="<x:out select="$milestone/content_hidden"/>"/>
            </td>
        </tr>
        <c:set value="${index+1}" var="index" scope="page"/>
    </x:forEach>
    <script type="text/javascript">
        showAllDateTag("tblMileStones");
    </script>
    </tbody>
</table>
<table width="98%" align="center">
    <tr ><td>
        <input class="button_02" name="cmdAddbefore" type=button value="添加" onclick="if(checkTabLimit('tblMileStones',5,'项目进度计划信息最多只能填写5条')){addNewRow_time('tblMileStones');showDateTag('tblMileStones');}try{top.resizeFrame();}catch(e){};">
        <input class="button_02" name="cmdMovePrev" type=button value="上移" onclick="movePrev2('tblMileStones','selMileStones');assignmentDate();">
        <input class="button_02" name="cmdMoveNext" type=button value="下移" onclick="moveNext2('tblMileStones','selMileStones');assignmentDate();">
        <input class="button_02" name="cmddel" type=button  value="删除" onclick="deleteSelectedRow2('tblMileStones','项目进度计划');assignmentDate();">
    </td></tr>
</table>



<script type="text/javascript">
    $(function() {
        $("#tblMileStones tr:even").addClass("li_1");
        $("#tblMileStones tr:odd").addClass("li_2");
        var flag = '${flag}';
        if(flag ==1){
            initRow();
        }
    });
    function initRow(){
        var i =1;
        for(i=1;i<5;i++){
            addNewRow_time('tblMileStones');
            showDateTag('tblMileStones');
        }
    }

    //把进度计划开始结束时间赋给基本信息里的开始结束时间
    function assignmentDate(){
        if("${sub_grant_code}" == '4592' || "${sub_grant_code}" == '4593' || "${sub_grant_code}" == '3119' || "${sub_grant_code}" == '3374' || "${sub_grant_code}" == '3327'|| "${sub_grant_code}" == '3328'|| "${sub_grant_code}" == '3329'|| "${sub_grant_code}" == '3113' || "${sub_grant_code}" == '5993' ||  "${sub_grant_code}" == '5994'  || "${sub_grant_code}" == '3116' || "${sub_grant_code}" == '3115' || "${sub_grant_code}" == '4594'
            || "${sub_grant_code}" == '3336'|| "${sub_grant_code}" == '3337'|| "${sub_grant_code}" == '3338' || "${sub_grant_code}" == '4992' || "${sub_grant_code}" == '5192'||"${sub_grant_code}" == '3117' ||"${sub_grant_code}"=='3767'||"${sub_grant_code}"=='3766'||"${sub_grant_code}"=='3118' ||"${sub_grant_code}"=='3349'||"${sub_grant_code}"=='3361' || "${sub_grant_code}" == '3355'|| "${sub_grant_code}" == '3356'||  "${sub_grant_code}" == '6593'||  "${sub_grant_code}" == '6594'){
            var start_date = $("#tblMileStones").find("tr:eq(2)").find(":[name$='/start_date']").val();
            var end_date = $("#tblMileStones").find("tr:last").find(":[name$='/end_date']").val();
            $("#start_date").val(start_date);
            $("#end_date").val(end_date);
        }
    }
    //重新计算行号
    function refreshRowINdex2(tblId){


        $("#"+tblId+" tr").each(function(){

                var seq=$(this).get(0).rowIndex;//获得行数
                if(seq>1){//如果有行  显示时display行不计入类，故只减1

                    seq=seq-1;
                    var seq_no=$(this).find("[name$='seq_no']");
                    if(seq_no.is("span"))
                        seq_no.html(seq);
                    else
                        seq_no.val(seq);

                    seq=""+(seq-1);
                    if(seq.length==1)
                        seq="0"+seq;
                    //替换相应的name参数的seq
                    $(this).find("input,span,textarea,select").each(function(){
                        var name=$(this).attr("name");
                        if(name!=null&&name!=""){
                            name=name.replace(/\[\d*\]/g,"["+seq+"]");
                            $(this).attr("name",name);
                        }
                        var id=$(this).attr("id");
                        if(id!=null&&id!=""){
                            id=id.replace(/\[\d*\]/g,"["+seq+"]");
                            $(this).attr("id",id);
                            id=id.replace(/\d+/g,""+seq+"");
                            $(this).attr("id",id);
                        }
                        var className=$(this).attr("class");
                        var seq1 = parseFloat(seq);
                        if(className!=null&&className!=""&&className.indexOf("dateCompareAfterEStep")!=-1){
                            className=className.replace(/\[\d*\]/g,"["+seq+"]");
                            if(seq1<10) {
                                className = className.replace(/dateCompareAfterEStep:milestone_start_date_\[\d*\]/g, "dateCompareAfterEStep:milestone_start_date_[" + 0 + (seq1 + 1) + "]");
                                className = className.replace(/dateCompareAfterEStep:milestone_end_date_\[\d*\]/g, "dateCompareAfterEStep:milestone_end_date_[" + 0 + (seq1 + 1) + "]");
                            }else{
                                className = className.replace(/dateCompareAfterEStep:milestone_start_date_\[\d*\]/g, "dateCompareAfterEStep:milestone_start_date_[" + (seq1 + 1) + "]");
                                className = className.replace(/dateCompareAfterEStep:milestone_end_date_\[\d*\]/g, "dateCompareAfterEStep:milestone_end_date_[" + (seq1 + 1) + "]");
                            }
                            $(this).attr("class",className);
                        }
                        if(className!=null&&className!=""&&className.indexOf("dateCompareAfterEStep")==-1){
                            className=className.replace(/\[\d*\]/g,"["+seq+"]");
                            $(this).attr("class",className);
                        }
                    });
                }
            }
        );

    }
    function moveNext2(tblId,selName) {
        if (!selName)
            selName = "";
        if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
            scmWarn(irisNotes.nextWarn);
            return false;
        }
        if ($("#" + tblId + " tr").length <= 2) {
            return false;
        }
        var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
            .parents("tr").first();// 取得被选中的行
        var trNext = trChecked.next();
        var index = trChecked.get(0).rowIndex;// 获得行号
        if (index == $("#" + tblId + " tr").length - 1) {// 如果是第一行
            scmWarn(irisNotes.tabelMoveWarn2);
            return false;
        }
        //trChecked.remove();
        trNext.after(trChecked);
        trChecked.find(":radio[name*='" + selName + "']").attr("checked", "true");
        refreshRowINdex2(tblId);
    }

    /**
     * 上移行
     * @param tblId
     * @returns {Boolean}
     */
    function movePrev2(tblId,selName) {

        if (!selName)
            selName = "";
        if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
            scmWarn(irisNotes.prevWarn);
            return false;
        }
        if ($("#" + tblId + " tr").length <= 2)
            return false;
        var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
            .parents("tr").first();// 取得被选中的行
        var trPrev = trChecked.prev();// 取得上一行
        var index = trChecked.get(0).rowIndex;// 获得行号
        if (index <= 2) {// 如果是第一行
            scmWarn(irisNotes.tabelMoveWarn1);
            return false;
        }
        //trChecked.remove();
        trPrev.before(trChecked);
        trChecked.find(":radio[name*='" + selName + "']").attr("checked", 'true');
        refreshRowINdex2(tblId);
    }

    /**
     * 删除一行
     * @param radioId
     */
    function deleteSelectedRow2(tableId,message,nummin,warnMsg,selName){
        if(!selName)selName="";
        var tr=$("#"+tableId+" :radio[name*='"+selName+"']:checked").parents("tr");
        if(nummin==null)
            nummin=0;
        var length=tr.length;
        if(tr.length==0)
            tr=$("#"+tableId+" tr").filter(":last");
        else if(tr.length>1)
            tr=tr.first();

        if(tr.get(0).rowIndex-1==nummin){
            scmWarn(irisNotes.delWarn1);
            return false;
        }
        if(length==0){

            scmWarn(irisNotes.delWarn2);

            return false;
        }
        if(!confirm(messageTip.deleteTip+message+"？"))
            return false;
        tr.remove();
        refreshRowINdex2(tableId);
        return true;
    }
    function addNewRow_time(tableId,url,title)
    {
        if(url!=null&&url!=""){
            showThickBox(url,title);

        }//跳转页面
        else
            addNewRowDeal_time($("#"+tableId));
    }
    function addNewRowDeal_time(table)
    {
        var sLine = [];
        var tbid = table.attr("id");
        var maxLinNum=table.find("tr").length-2;;//获得行数，减去表头和隐藏行
        var lineNum=""+(maxLinNum+1);
        var lineNum2=""+(maxLinNum+1);
        var sl = sLine[tbid];
        if(sl == undefined){
            sLine[tbid] = 1;
            sl = sLine[tbid];
        }else{
            sLine[tbid] ++;
            sl = sLine[tbid];
        }
        var tlineNum = "";

        var addHtml=table.find("tr")[1].innerHTML;//获得隐藏行的html,查找第二行
        addHtml=addHtml.replace(/\[index\]/g,lineNum);
        lineNum = (parseInt(lineNum, 10)-1).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
        if (lineNum.length==1){//如果是个位数，前面补0
            lineNum="0"+lineNum;
        }
        lineNum2 = (parseInt(lineNum2, 10)-0).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
        if (lineNum2.length==1){//如果是个位数，前面补0
            lineNum2="0"+lineNum2;
        }
        addHtml=addHtml.replace(/\[0\]/g,"["+lineNum+"]");//替换html中行号
        addHtml=addHtml.replace(/\[1\]/g,"["+lineNum2+"]");//替换html中行号
        addHtml=addHtml.replace(/\|/g,"/");//替换html中节点/的代替符"|"
        table.append("<tr>"+addHtml+"</tr>");//将html增加到最后

    }
    //验证两个日期大小(d1>=d2) 项目计划进度的第二行开始时间不能小于第一行的结束时间
    function irisValDateAfterEByObjStep(d1, d2) {
        var str1 = getTagValueByJq(d1);
        var str2 = getTagValueByJq(d2);
        if (str1 == "" || str2 == "")
            return true;
        var flag = true;
        if (!irisValDateByObjPure(d1))
            flag = false;
        if (!irisValDateByObjPure(d2))
            flag = false;
        if (!flag)
            return true;
        var firstDate;
        var secondDate;
        if (locale == "en_US") {
            d1Array = (str1.split("/"));
            d2Array = (str2.split("/"));
            firstDate = new Date(d1Array[2], getDateNumber(d1Array[0]) - 1,
                getDateNumber(d1Array[1]));
            secondDate = new Date(d2Array[2], getDateNumber(d2Array[0]) - 1,
                getDateNumber(d2Array[1]));
        } else {
            d1Array = (str1.split("-"));
            d2Array = (str2.split("-"));
            firstDate = new Date(d1Array[0], getDateNumber(d1Array[1]) - 1,
                getDateNumber(d1Array[2]));
            secondDate = new Date(d2Array[0], getDateNumber(d2Array[1]) - 1,
                getDateNumber(d2Array[2]));
        }
        if (firstDate > secondDate)
            return true;
        else {
            var strLaber2 = "";
            if (d2.attr("label") != null) {
                strLaber2 = d2.attr("label");
            }

            var id="";
            if(d1.attr("id")!=null && d1.attr("name").indexOf("start_date")>1){
                id=d1.attr("id").substring(22,24);
            }
            if(d1.attr("id")!=null && d1.attr("name").indexOf("end_date")>1){
                id=d1.attr("id").substring(20,22);
            }
            if(id.substring(1,1)=='0'){
                id=id.substring(1,2);
            }
            id=parseInt(id)+1;

            var strLaber1 = "";
            if (d1.attr("label") != null) {
                strLaber1 = d1.attr("label");
            }
            strLaber1="第"+id+"行"+strLaber1;
            irisValaddMsg(strTitle
                + messageTip.dateBeforeD.replace("[d1]", strLaber2).replace("[d2]", strLaber1));

            return false;
        }
    }

    $.datepick.selectDate=function(target, elem) {
        var inst = $.data(target, this.dataName);
        if (inst && !this.isDisabled(target)) {
            var date = this.retrieveDate(target, elem);
            var multiSelect = inst.get('multiSelect');
            var rangeSelect = inst.get('rangeSelect');
            if (multiSelect) {
                var found = false;
                for (var i = 0; i < inst.selectedDates.length; i++) {
                    if (date.getTime() == inst.selectedDates[i].getTime()) {
                        inst.selectedDates.splice(i, 1);
                        found = true;
                        break;
                    }
                }
                if (!found && inst.selectedDates.length < multiSelect) {
                    inst.selectedDates.push(date);
                }
            }
            else if (rangeSelect) {
                if (inst.pickingRange) {
                    inst.selectedDates[1] = date;
                }
                else {
                    inst.selectedDates = [date, date];
                }
                inst.pickingRange = !inst.pickingRange;
            }
            else {
                inst.selectedDates = [date];
            }
            inst.prevDate = $.datepick.newDate(date);
            this._updateInput(target);
            $(target).change();
            if (inst.inline || inst.pickingRange || inst.selectedDates.length <
                (multiSelect || (rangeSelect ? 2 : 1))) {
                this._update(target);
            }
            else {
                this.hide(target);
            }
        }
    }
</script>